package frontend.model.admin;

import backend.model.other.LegalHoliday;
import frontend.model.base.UIModel;

import java.util.Calendar;
import java.util.Date;

public class LegalHolidayUIModel implements UIModel<LegalHoliday>
{
    private Date date;
    private String description;

    private LegalHoliday legalHoliday;

    public LegalHolidayUIModel() {
        legalHoliday = new LegalHoliday();
    }

    public LegalHolidayUIModel(LegalHoliday legalHoliday) {
        this.legalHoliday = legalHoliday;
        populateFieldsFromDBModel();
    }

    @Override
    public LegalHoliday getDBModel() {
        return legalHoliday;
    }

    @Override
    public void populateDBModelFromFields() {
        legalHoliday.setDate(date);
        legalHoliday.setDescription(description);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        legalHoliday.setYear(calendar.get(Calendar.YEAR));
    }

    @Override
    public void populateFieldsFromDBModel() {
        date = legalHoliday.getDate();
        description = legalHoliday.getDescription();
    }

    public Date getDate() {
        return date;
    }
}
